﻿using Hotel.Model;

namespace Hotel.DAL
{
    public class AdminDAL
    {
        public AdminDAL(HotelContext hotelContext)
        {
            HotelContext = hotelContext;
        }

        public HotelContext HotelContext { get; }


        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <param name="userName">管理员账号</param>
        /// <param name="userPwd">管理员密码</param>
        /// <returns></returns>
        public dynamic Login(string userName,string userPwd)
        {
            try
            {
                var count = HotelContext.admins.Where(x => x.Name == userName).Count();
                if (count == 0)
                {
                    return -1;//用户名不存在
                }
                else
                {
                    var res = HotelContext.admins.Where(x => x.Pwd == userPwd).Count();
                    if (res == 0)
                    {
                        return -2;//密码错误
                    }
                    else
                    {
                        var info = HotelContext.admins.Where(x => x.Name == userName && x.Pwd == userPwd).FirstOrDefault();
                        return info;
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        public int Login1()
        {
            return 237823;
        }
    }
}
